<?php

namespace app\models;

use Yii;
use yii\db\Query;
/**
 * This is the model class for table "{{%cart}}".
 *
 * @property integer $id
 * @property integer $uid
 * @property integer $create_at
 * @property integer $status
 */
class ListQg extends \yii\db\ActiveRecord {

  public static function tableName()
    {
        return '{{%base_goods_qg}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['status', 'qgsl', 'xj', 'cs', 'qym', 'statuses', 'sp_id'], 'integer'],
            [['qgczrz', 'mjgsdz', 'mjshdz'], 'string'],
            [['sczdj', 'cgjg'], 'number'],
            [['spm', 'gg', 'bzqyq', 'dhrq', 'wlsyq', 'fbsj', 'mjgs', 'mjlxr'], 'string', 'max' => 128],
            [['mjlxrdh'], 'string', 'max' => 25]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'qgd_id' => '求购单ID',
            'status' => '求购单状态',
            'qgczrz' => '求购操作日志',
            'spm' => '商品名',
            'gg' => '规格',
            'sczdj' => '市场指导价',
            'qgsl' => '求购数量',
            'bzqyq' => '保质期要求',
            'cgjg' => '采购价格',
            'xj' => '包装要求 是否新旧 新1 旧0',
            'cs' => '残损  完好1 残存0 ',
            'qym' => '区域码  有1 无0',
            'dhrq' => '到货日期要求',
            'wlsyq' => '物流商要求',
            'fbsj' => '发布时间',
            'mjgs' => '买家公司',
            'mjgsdz' => '买家公司地址',
            'mjlxr' => 'Mjlxr',
            'mjlxrdh' => '买家联系人电话',
            'mjshdz' => '买家收货地址',
            'statuses' => '0下架  1上架',
            'sp_id' => 'Sp ID',
        ];
    }
    
    public static function selBasegoods($array,$condition,$tag,$pages,$page1) {
            $pages=(int)$pages;
        
            $basegoods = (new Query())->select('a.*,b.*,c.company_name,c.phone')->from("dh_base_goods_qg as a")->leftJoin('dh_base_goods AS b','a.sp_id = b.id')->leftJoin("dh_sys_users as c","a.uid=c.id")->
                    Where($array)->andWhere('1=1'.$condition)->orderBy($tag)->limit($page1)->offset($pages)->all();
            
            return $basegoods;
	
    }
    
    
    
     public static function listBaseGoods($array,$condition) {
            
        $total = (new Query())->select('a.*,b.*')->from("dh_base_goods_qg as a")->
                        leftJoin('dh_base_goods AS b','a.sp_id = b.id')->Where($array)->andWhere('1=1'.$condition)->count();
        
        return $total;
    }
  
}
